/*
 * $Id: StepTimeDAO.java,v 1.9 2009/07/10 15:18:36 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.CfgStepType;
import com.ge.healthcare.autosc.common.database.pojo.HstStepTime;
import com.ge.healthcare.autosc.common.pojo.StepTimeNType;

/**
 * @author 212042764
 * 
 */
public class StepTimeDAO extends BaseDAO implements IStepTimeDAO {

	/**
	 * Eclipse generated
	 */
	private static final long serialVersionUID = 1403939443956684678L;

	public StepTimeDAO() {
		super(HstStepTime.TABLE_NAME);
	}

	public HstStepTime getStepTimeByID(Long stepTimeId) {
		Object stepTime = findObjectByID(HstStepTime.COL_STEP_TIME_ID,
				stepTimeId);
		if (!ASCUtil.isNullOrEmptyObject(stepTime)) {
			return (HstStepTime) stepTime;
		}
		return null;
	}

	public HstStepTime getStepTimeByStepTypeId(Long stepTypeId) {
		Object request = findObjectByID(HstStepTime.COL_STEP_TYPE_ID,
				stepTypeId);
		if (!ASCUtil.isNullOrEmptyObject(request)) {
			return (HstStepTime) request;
		}
		return null;
	}

	public List<HstStepTime> getStepTimeByObjectId(Long objectId) {
		if (ASCUtil.isNullOrEmptyObject(objectId)) {
			return null;
		}
		List<?> resultLst = findByProperty(HstStepTime.COL_OBJECT_ID, objectId);
		if (ASCUtil.isNullOrEmptyList(resultLst)) {
			return null;
		}
		List<HstStepTime> stepTimeLst = new ArrayList<HstStepTime>();
		for (int iCount = 0; iCount < resultLst.size(); iCount++) {
			stepTimeLst.add((HstStepTime) resultLst.get(iCount));
		}
		return stepTimeLst;
	}

	public ArrayList<StepTimeNType> getStepTimeNTypeGreaterThanId(
			Long stepTimeId) {
		StringBuffer query = new StringBuffer();
		query.append("select sTime");// .append(HstStepTime.COL_STEP_TIME_ID);
		query.append(", sType.").append(CfgStepType.COL_STEP_TYPE);
		query.append(", sType.").append(CfgStepType.COL_SERVER_NAME);
		query.append(" from ");
		query.append(CfgStepType.TABLE_NAME).append(" as sType , ");
		query.append(HstStepTime.TABLE_NAME).append(" as sTime");
		query.append(" where ");
		query.append("sType.").append(CfgStepType.COL_ID).append(" = ");
		query.append("sTime.").append(HstStepTime.COL_STEP_TYPE_ID);
		query.append(" and ").append("sTime.");
		query.append(HstStepTime.COL_STEP_TIME_ID).append(" > ?");

		logger.debug("query: " + query.toString() + " value: " + stepTimeId);
		List<?> values = getHibernateTemplate().find(query.toString(),
				stepTimeId);
		ArrayList<StepTimeNType> timeNType = new ArrayList<StepTimeNType>();
		for (Iterator<?> iterator = values.iterator(); iterator.hasNext();) {
			Object[] list = (Object[]) iterator.next();
			timeNType.add(new StepTimeNType((HstStepTime) list[0],
					(String) list[1], (String) list[2]));
		}
		return timeNType;
	}

	public void save(Object pojo) {
		super.save(pojo);
	}

	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

	public void deleteByID(Object pojo) {
		super.deleteByID(pojo);
	}

	public void refresh(Object pojo) {
		super.refresh(pojo);
	}

}
